package com.scs.application.modules.finance.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.modules.finance.dto.PeriodCreateDTO;
import com.scs.application.modules.finance.entity.Period;
import com.scs.application.modules.finance.service.PeriodService;
import com.scs.application.modules.sys.model.RestResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 *  前端控制器
 * </p>
 */
@RestController
@RequestMapping("/finance/period")
public class PeriodController extends CrudController<PeriodService, Period>{

    /**
     * 自动生成结算周期
     * @param periodCreateDTO
     * @return
     */
    @PostMapping("/autoCreate")
    public RestResult autoCreatePeriod(@RequestBody @Valid PeriodCreateDTO periodCreateDTO) {
        return RestResult.ok(service.autoCreatePeriod(periodCreateDTO));
    }

    @GetMapping("/getByPeriod")
    public RestResult getByPeriod(String period) {
        Period period1 = service.getOne(new QueryWrapper<Period>().eq("period", period));
        return RestResult.ok("获取数据成功", period1);
    }
}
